package manage.action;

import m.common.action.ActionMeta;
import m.common.action.RequestMeta;
import m.common.action.VueResult;
import m.common.model.util.ModelUpdateUtil;
import m.html.VueListResult;
import m.html.element.attr.ButtonType;
import m.html.list.ListButton;
import m.html.list.SuccessMethod;
import m.system.cache.CacheUtil;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import manage.model.AdminColumn;

@ActionMeta(name="manage/adminColumn")
public class AdminColumnAction extends ManageAction{
    @RequestMeta(params = {"oid","adminOid","columnsParamKey"})
    public JSONMessage doDelete(String oid,String adminOid,String columnsParamKey) throws MException {
        AdminColumn model=new AdminColumn();
        model.setOid(oid);
        ModelUpdateUtil.deleteModel(model);
        CacheUtil.clear(AdminColumn.class,adminOid,columnsParamKey);
        return new JSONMessage(0,"操作成功");
    }
    /*
     * 用户列管理列表
     */
    public VueResult allList() throws Exception {
        VueListResult result=getVueListResult("用户列管理", AdminColumn.class, actionUrl("allList"));
        result.setHeight(-1);
        result.setSelection("oid",false);
        result.addCol(toIndexColumn());
        result.addCol(toTextColumn("真实姓名", "admin.realname", 100, true));
        result.addCol(toTextColumn("请求的url", "url", 250, true));
        result.addCol(toTextColumn("显示参数", "viewParams", 350, true));
        result.addButton(
            ListButton.ajax("删除", ButtonType.ERROR,actionUrl("doDelete"), SuccessMethod.REFRESH)
            .addParam("oid","oid").addParam("adminOid","admin.oid").addParam("columnsParamKey","columnsParamKey")
            .setConfirm("确定要删除吗？")
        );
        return result;
    }
}
